

window.onload = function(){
    //
    //document.getElementById("inputUrl").onkeypress=onkeypressOpenWindow;
    //document.getElementById("testInput").onkeypress=onkeypress;
}

function checkEmp(){
    //alert("emp is:" + JSON.stringify(window.emp))
    emp.toast.show({msg:"emp is:" + JSON.stringify(window.emp)});
}

function onkeypress(event) {
    if (event.keyCode == 13) {
        //document.getElementById('testInput').blur();
        document.activeElement.blur();
    }
}

function showSoftKeyboard(){
    document.getElementById('testInput').focus();
    emp.window.showSoftKeyboard();
}

function windowclose(wid) {
    emp.window.close({
        id: wid
    })
}

function openPdfFile(){
    emp.iapppdf.openWebPdfFile({
        fileUrl:'http://menhu-dev.thuniwhir.com/upload/pdfFile/ADC0809_cn.pdf',
        uploadUrl:"http://menhu-dev.thuniwhir.com/menhu-demo/file/upload",
        uploadParams:{
          "path":"pdffile",
          "userFileNameFlag":"1"
        },
        readOnly:false,
        userName:'user',
        success:function(){
          emp.toast.show({msg:'success'})
        },
        error:function(err){
          if(err && err.code === 'CANCEL'){
            emp.toast.show({msg:'取消保存'});
          }else{
            emp.toast.show({msg:'error:'+(err||{}).msg})
          }
        }
    })
}

//H5侧边栏打开
window.onH5SidebarShow=function(){
    emp.toast.show({msg:"window.onH5SidebarShow"})
}
//H5侧边栏关闭
window.onH5SidebarHide=function(){
    emp.toast.show({msg:"window.onH5SidebarHide"})
}

function h5SidebarClose(){
    emp.iapppdf.h5SidebarHide()
}
function h5SidebarSaveForm(){
    emp.iapppdf.h5SidebarSaveForm({field1:"test1",field2:"test2"})
}

function openPdfFileV2(layoutType='layout1'){
    var toolbar={
        tranInfo:{
         visible:true,
         iconVisible:true
        },
        addSign:{//加签
         visible:true,
         iconVisible:true
        },
        selfsend:{
         visible:true,
         iconVisible:true
        },
        pressInfo:{//催办
         visible:true,
         iconVisible:true
        },
        workflowUndo:{//撤回
         visible:true,
         iconVisible:true
        },
        sendToUndertaker:{//送承办单位
           visible:true,
           //url:"file:///android_asset/www/ApiTest.html?mustLoadingKeep=false",
           url:"http://www.baidu.com",
           title:"送承办单位",
           h5Title: "选择承办单位"
        },
        send:{//发送
         visible:true,
         iconVisible:true
        },
        withdraw:{//撤办
         visible:true,
         iconVisible:true
        },
        processRecord:{//流程记录
           visible:true,
           url:"file:///android_asset/www/ApiTest.html?mustLoadingKeep=false",
           //url:"http://www.baidu.com",
           title:"流程记录",
           exitSignWhenOpen:false,//打开时是否退出签批模式, default false
           saveSignWhenOpen:true,//打开时是否保存签批痕迹, default true
        },
        favorite:{//关注
           visible:true,
           value:true,
           api:"http://61.190.4.70:65119/defaultroot/pdfedite/favorite.controller"
        },
        annotationList:{//签批列表
         visible:true,
         isFlushRight:true
        },
        note:{//便签
           visible:true,
           editable:false,
           value:"关于对机动车和非道路移动机械排放污染防治条例",
           api:"http://61.190.4.70:65119/defaultroot/pdfedite/notetext.controller"
        },
        textAnnotationList:{//附注列表
           visible:true,
        },
        textAnnotation:{//附注
           visible:true,
        },
        cleanTextAnnotation:{//清空附注
           visible:true,
        },
        gotoHome:{//返回第一页
         visible:true,
        },
        gotoEnd:{//跳转到最后一页
         visible:true,
        },
        stamp:{//签章
         visible:true,
                checkStampCode:false,//是否校验章号,默认 true
        },
        delete_all:{//清空
           visible:true,
           visible_sign:true,/*签批模式可见,default is true 签批模式可见*/
           visible_view:false,/* 预览模式可见,default is true*/
        },
        undo:{//撤销
         visible:true,
        },
        redo:{//反撤销
         visible:true,
        },
        index:{//目录按钮
         visible:true,
        },
        mark:{//标注
           visible:true,
           visible_sign:false,/*签批模式可见，default is true*/
           visible_view:true,/*预览模式可见，default is true*/
        },
           markPenSetting:{//标注设置笔触
         visible:true,
         useCustom:true,/*是否使用自定义的笔触设置窗口，default is false*/
        },
        sign:{//签批
         visible:true,
         autoEnterSign:false,/*自动进入签批模式，default is false*/
        },
        penSetting:{//签批设置笔触
         visible:true,
         useCustom:true,/*是否使用自定义的笔触设置窗口，default is false*/
        }
    };
    openPdfFileBase(layoutType,toolbar)
}

function openPdfFileV2_toolbarPro(layoutType){
    var toolbar = {
      "container":{
          visible:true  //toolbar是否显示出来,true为显示,false为不显示
      },
        "stamp":{
            "visible":true,
            "checkStampCode":false
        },
      "sign":{
        "autoEnterSign":false,
        "hideTitleBarInSign":false
      },
//      "back":{//系统返回按键
//          "confirmExit":false, //退出提示
//          "confirmSave":false,//保存提示
//          "confirmUpload":false//文件上传提示
//         },
      "return":{//左上角返回按钮
          "confirmExit":false, //退出提示
          "confirmSave":false,//保存提示
          "confirmUpload":false//文件上传提示
       },
      "close":{
        "visible":true
       },
      "nextFile":{
          "visible":true,
          "keep":true,
      },
      "prevFile":{
           "visible":true,
          "keep":true,
       },
       "next":{
          "visible":true,
       },
       "prev":{
          "visible":true,
       },
       "findSameDocument":{//找同类公文
          "visible":true,//是否显示按钮
          "title":"找同类公文",//按钮文字
          "iconVisible":true,//是否显示图标
          "iconUrlOrBase64": "",//按钮图标的url或者base64数据
          "url":"file:///android_asset/www/iAppPdfTest.html",//打开的页面url
          "h5Title": "找同类公文"//打开webview页标题
       },
        "send":{//发送
            "visible":true,
            "iconVisible":true
        },
        "urgentCheckbox":{//加急
            "visible":true,
            "title":"加急"
        },

    }
    var toolbarPro={
        "visible":true,
        "isFlushRight":true,
        "buttons":[
            {
                "text":"undo",
                "action":"undo"
            },
            {
                "text":"redo",
                "action":"redo"
            },
            {
                "text":"退回修改",
                "action":"saveExit",
                "eventName":"back2modify",
                "mustConfirm":true,
                "confirmMsg":"确认退回修改吗？"
            },
            {
                "text":"无确认框",
                "action":"saveExit",
                "eventName":"back2modify",
                "mustConfirm":false,
                "confirmExit":false,
                "confirmSave":false,
                "confirmUpload":false,
                "confirmMsg":"确认退回修改吗？"
            },
            {
                "text":"保存",
                "action":"saveExit",
                "eventName":"back2modify",
                "mustConfirm":false,
                "confirmMsg":"确认退回修改吗？"
            },
            {
                "text": "审核",
                "variant": "contained",
                "action": "saveExit",
                "eventName": "back2modify",
                "preCondition":"hasSign",
                "preConditionWarnText":"请批示"
            },
            {
                "text": "openWebview",
                "action": "openWebview",
                "url": "file:///android_asset/www/iAppPdfTest.html"
            },
            {
                "text": "apiRequest",
                "action": "apiRequest",
                "url": "https://www.baidu.com",
                "apiParams":{
                    "test": true
                },
                "mustConfirm": true,
                "confirmMsg": "确认xxxx吗？"
            },
            {
                "text": "批示戳",
                "action": "stamp",
                "checkStampCode":false
            },
            {
                "text":"查看批注",
                "action":"annotationList"
            }
        ]
    };
    openPdfFileBase(layoutType,toolbar,toolbarPro)
}

var fuploadUrl1 = "http://menhu-dev.thuniwhir.com/menhu-demo/file/upload";
var fpdf1 = 'http://menhu-dev.thuniwhir.com/upload/pdfFile/2020050718170365417607037.pdf';
var fpdf2 = 'http://menhu-dev.thuniwhir.com/upload/pdfFile/ADC0809_cn.pdf';
var fpdf3 = 'http://menhu-dev.thuniwhir.com/upload/pdfFile/2018081414401058861256216.pdf';
var fpdf4 = "http://menhu-dev.thuniwhir.com/upload/pdfFile/X25045_CN.pdf";
var fpdf5 = "http://menhu-dev.thuniwhir.com/upload/pdfFile/ADC0832_CH.pdf";
var fdoc1 = 'http://menhu-dev.thuniwhir.com/upload/jingeUpload/pdf/2018081414401058861256225.doc';
var fxls1 = "http://menhu-dev.thuniwhir.com/upload/pdfFile/test.xls";
var fdocx1 = "http://menhu-dev.thuniwhir.com/upload/pdfFile/test.docx";

var getNotesUrl1 = "http://10.10.20.4:8090/iapppdf_notes_data.json";

function openPdfFileBase(layoutType,toolbar,toolbarPro){
    var options ={
        "supervisors":[
            {
                "name":"张测试",
                "id":"leaderId1",
                "isred":0,
                "hassign":0
            },
            {
                "name":"李研发",
                "id":"leaderId2",
                "isred":0,
                "hassign":0
            }
        ],
        "sign":{
            "closeSignature": true,
            "backpress": "exitSign"
        },
         layout:layoutType,
         uploadUrl:fuploadUrl1,
         uploadParams:{
           "path":"pdffile",
           "userFileNameFlag":"1"
         },
         title:{
             visible:true,
             text:"标题测试"
         },
         readOnly:false,
         "h5Sidebar":{
            "visible":true,//侧边栏按钮是否可见
            "url":"file:///android_asset/www/iAppPdfTest.html",//侧边栏打开的H5 url
            "cookie":"cookie1=xxxxxxxxxxxx; cookie2=xxxxxxxxxxxx",//H5webview cookie
            "text":"查看公文和附件",//按钮文字
            "textSize":14,//文字大小
            "textColor":"#FFFFFF",//文字颜色
            "backColor":"#FF8942",//背景颜色
         },
         "outlineSidebar":{
             "visible":false,//侧边栏按钮是否可见
             "text":"目录",//按钮文字
             "textSize":14,//文字大小
             "textColor":"#FFFFFF",//文字颜色
             "backColor":"#C8C7C7",//背景颜色
         },
         userName:'user',
         attachments:[
            {
                 id:'id1',title:'title1',time:'2019-04-19 12:00:00',size:'8MB',
                 url:fpdf1,
                 isLocked:true
            },
            {
                id:'id1',title:'title1',time:'2019-04-19 12:00:00',size:'8MB',
                url:fpdf2,
                isLocked:true
            },
            {id:'id2',title:'title2',time:'2019-04-19 12:00:00',size:'4MB',
               url:fpdf3
            },
            {id:'id2',title:'title3',time:'2019-04-19 12:00:00',size:'5MB',
                url:fpdf4
            },
            {
               id:'id2', title:'pdf 只读',time:'2019-04-19 12:00:00',size:'5MB',
               url:fpdf5,
               //url:"http://www.fxdzw.com/xpzl/pdf/ADC0832_CH.pdf",
               readOnly:true
            },
            {
                id:'id2',title:'附件doc',time:'2019-04-19 12:00:00',size:'5MB',
               type:'preview',
               preview:{
                 url:fdoc1
               }
            },
            {
             id:'id2',title:'附件doc',time:'2019-04-19 12:00:00',size:'5MB',
             type:'doc',
             doc:{
               hostUrl:"http://www.kinggrid.com:8080/iWebOffice2009/OfficeServer.jsp",//金格服务器url
               fileId:"1487055329034",//需要编辑的文件对应的文件id  1490444371683 1487055329034
               isPGFFormat:"0",//是否以PGF格式打开
               readOnly:"0",//是否只读模式打开
               userName:"test1",//当前用户名
               isScreenshotForbid:"0",//是否防截屏
               enterReviseMode:"0",//是否进入修订模式
               showReviewingPane:"1",//是否显示修订痕迹右侧边栏,不传本参数时默认不显示,只有当enterReviseMode:"1",开启修订模式时,本参数才有效.
               hideFileMenu:"0",//是否隐藏文件菜单
               hideCopyAndCut:"0",//是否隐藏复制和剪切功能
               hideShareAndSaves:"0"//是否隐藏分享和另存为功能
             }
           },
           {
             id:'id2',title:'附件doc只读',time:'2019-04-19 12:00:00',size:'5MB',
             type:'doc',
             doc:{
             hostUrl:"http://www.kinggrid.com:8080/iWebOffice2009/OfficeServer.jsp",//金格服务器url
             fileId:"1487055329034",//需要编辑的文件对应的文件id  1490444371683 1487055329034
             isPGFFormat:"0",//是否以PGF格式打开
             readOnly:"1",//是否只读模式打开
             userName:"test1",//当前用户名
             isScreenshotForbid:"0",//是否防截屏
             enterReviseMode:"1",//是否进入修订模式
             showReviewingPane:"1",//是否显示修订痕迹右侧边栏,不传本参数时默认不显示,只有当enterReviseMode:"1",开启修订模式时,本参数才有效.
             hideFileMenu:"0",//是否隐藏文件菜单
             hideCopyAndCut:"0",//是否隐藏复制和剪切功能
             hideShareAndSaves:"0"//是否隐藏分享和另存为功能
           }}
      ],
     success:function(data){
       emp.toast.show({msg:"emp.iapppdf.openWebPdfFileV2.success,data is:"+JSON.stringify(data)})
     },
     error:function(err){
        emp.toast.show({msg:"emp.iapppdf.openWebPdfFileV2.error,data is:"+JSON.stringify(err)})
     },
      event:function(name,data){
         emp.toast.show({msg:"emp.iapppdf.openWebPdfFileV2.event:name is"+name+",data is:"+JSON.stringify(data)})
      }
    };
    if(toolbar){
        options.toolbar = toolbar
    }
    if(toolbarPro){
        options.toolbarPro = toolbarPro
    }
    emp.iapppdf.openWebPdfFileV2(options)
}

function openPdfFileV2_szf(layoutType){
  emp.iapppdf.openWebPdfFileV2({
  "uploadUrl":"http://133.1.240.59:8800/defaultroot/doc/savePdf.controller?path=tempfile/temppdf/&userKey=chenjn&domainId=0&recordId=1526024&workStatus=0&userId=266268&userIdentity=1",
  "uploadParams":{"userFavorite":true},
  "userName":"陈吉宁",
  "viewMode":"VSCROLL",
  "export_annotation":true,
  "textAnnotAllowUser":"陈吉宁,司政",
  "toolbar":{
    "sendToLeader":{"visible":false,"iconVisible":true,"title":"送领导批示","confirmExit":false},
    "withdraw":{"visible":false,"iconVisible":true,"confirmExit":false},
    "workflowUndo":{"title":"撤办","iconVisible":true,"visible":false,"confirmExit":false},
    "send":{"title":"发送","visible":true,"iconVisible":true,"confirmExit":false},
    "finish":{"visible":false,"iconVisible":true,"value":"办结","confirmExit":false},
    "annotationList":{"visible":true},
    "note":{"visible":true,"editable":true,"value":"","api":getNotesUrl1,"multNotes":true,"title":"便签"},
    "favorite":{"visible":true,"value":"","api":"http://133.1.240.59:8800/defaultroot/mhpdfedite/setFocus.controller?recordId=1526024&focusStatus=0&has_favorite=false&userKey=chenjn&domainId=0&userId=266268&orgId=236297&orgName=北京市政府.市政府领导.市领导&userName=陈吉宁","title":"关注"},
    "processRecord":{"visible":true,"url":"http://133.1.240.59:8800/defaultroot/DDFlowLogView/flowLogView.controller?userKey=chenjn&processInstanceId=29211314","title":"流程记录","exitSignWhenOpen":false,"saveSignWhenOpen":true,"confirmExit":false},
    "relatedArticle":{"visible":false,"api":"http://133.1.240.59:8800/defaultroot/mhpdfedite/getRelationProcess.controller?recordId=1526024&moduleId=3&userKey=chenjn"},
    "textAnnotationList":{"visible":true},
    "textAnnotation":{"visible":false},
    "cleanTextAnnotation":{"visible":false},
    "stamp":{"visible":false,"checkStampCode":false,"visibleInReadOnly":true},
    "penSetting":{"visible":true,"useCustom":true},
    "mark":{"visible":false,"visible_sign":false,"visible_view":true,"visibleInReadOnly":true,"confirmExit":false},
    "markPenSetting":{"visible":false,"useCustom":true,"visibleAlways":true},
    "sign":{"visible":true,"autoEnterSign":true,"hideSignTool":true,"showDeleteRect":true,"hideTitleBarInSign":false,"showAnnotToast":true,"confirmExit":false},
    "gotoHome":{"visible":true},
    "gotoEnd":{"visible":true},
    "prev":{"visible":false},
    "next":{"visible":false},
    "delete_all":{"visible":true,"visible_sign":true,"visible_view":false},
    "return":{"confirmExit":false},
    "back":{"confirmExit":false,"confirmSave":false},
    "prevFile":{"visible":true},
    "nextFile":{"visible":true},
    "index":{"visible":false}},
    "attachments":[
        {"title":"批办单","open":true,"type":"pdf","readOnly":false,"url":fpdf5,"pdf":{"workflowUndo":false}},
        {"title":"附件","child":[
            {"id":"2020062809515084168182291.docx","title":"测试使用的word.docx","time":"2020年06月28日","size":"15.8 KB","url":"","signStatus":"","type":"preview","preview":{"url":fdocx1},"pdf":{"workflowUndo":false}},
            {"id":"2020062809515337785560941.xls","title":"测试使用excel.xls","time":"2020年06月28日","size":"24 KB","url":"","signStatus":"","type":"preview","preview":{"url":fxls1},"pdf":{"workflowUndo":false}},
            {"id":"2020062809520835950596647.pdf","title":"批办单.pdf","time":"2020年06月28日","size":"259.2 KB","url":fpdf1,"signStatus":"no","type":"pdf","readOnly":false,"canFavor":false,"uploadUrl":"http://133.1.240.59:8800/defaultroot/doc/savePdf.controller?signType=1&path=tempfile/temppdf&userKey=chenjn&domainId=0&recordId=1526024&workStatus=0&userId=266268&userIdentity=1","pdf":{"workflowUndo":false}},
            {"id":"2020062809521089462012255.pdf","title":"测试使用的正文.pdf","time":"2020年06月28日","size":"52.6 KB","url":fpdf2,"signStatus":"no","type":"pdf","readOnly":false,"canFavor":false,"uploadUrl":"http://133.1.240.59:8800/defaultroot/doc/savePdf.controller?signType=1&path=tempfile/temppdf&userKey=chenjn&domainId=0&recordId=1526024&workStatus=0&userId=266268&userIdentity=1","pdf":{"workflowUndo":false}}
        ]},
        {"title":"参考文件","child":[
            {"id":"2020062809561573613242231.xls","title":"测试使用excel.xls","time":"2020年06月28日|","size":"24 KB","url":"","type":"preview","preview":{"url":fxls1},"pdf":{"workflowUndo":false}},
            {"id":"2020062809561844998537602.docx","title":"测试使用的word.docx","time":"2020年06月28日|2020年06月28日|","size":"15.8 KB","url":"","type":"preview","preview":{"url":fdocx1},"pdf":{"workflowUndo":false}},
            {"id":"2020062809562374911951880.pdf","title":"测试使用的正文.pdf","time":"2020年06月28日|2020年06月28日|2020年06月28日|","size":"52.6 KB","url":"","type":"preview","preview":{"url":fpdf3},"pdf":{"workflowUndo":false}},
            {"id":"2020062809564171368753754.pdf","title":"批办单.pdf","time":"2020年06月28日|2020年06月28日|2020年06月28日|2020年06月28日|","size":"259.2 KB","url":"","type":"preview","preview":{"url":fpdf4},"pdf":{"workflowUndo":false}}
        ]}
    ],
    "supervisors":[{"name":"","id":"1","isred":0,"hassign":0}],
    "segment":{"seg1Text":"批办单","seg2Text":"附件"}
  })
}

function getQueryString(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var match = window.location.search.substr(1).match(reg);
    if(match!=null){
        return  decodeURI(match[2]);
    }
    return null;
}

function openFileInner1(type){
    var pdf ={
        "iapppdfId":getQueryString("iapppdfId"),//从url里面获取当前签批的标识
        "type":"pdf",
        "id":'id1',
        "title":'title1',
        "time":'2019-04-19 12:00:00',
        "size":'8MB',
        "url":'http://menhu-dev.thuniwhir.com/upload/pdfFile/2018081414401058861256216.pdf',//文件url
		"uploadUrl":"http://menhu-dev.thuniwhir.com/menhu-demo/file/upload",//文件上传的地址
        "autoEnterSign":true,//自动进入签批模式
        "autoEnterMark":false,//自动开启标注功能
        "readOnly":false,//只读
    }
    emp.iapppdf.openFileInner(pdf)
}

function openFileInner2(type){
    var pdf ={
        "iapppdfId":getQueryString("iapppdfId"),//从url里面获取当前签批的标识
        "type":"pdf",
        "id":'id2',
        "title":'title2Inner',
        "time":'2019-04-19 12:00:00',
        "size":'8MB',
        "url":'http://menhu-dev.thuniwhir.com/upload/pdfFile/X25045_CN.pdf',//文件url
		"uploadUrl":"http://menhu-dev.thuniwhir.com/menhu-demo/file/upload",//文件上传的地址
        "autoEnterSign":true,//自动进入签批模式
        "autoEnterMark":false,//自动开启标注功能
        "readOnly":false,//只读
    }
    emp.iapppdf.openFileInner(pdf)
}

function openFileInner3(type){
    var pdf ={
        "iapppdfId":getQueryString("iapppdfId"),//从url里面获取当前签批的标识
        "type":"pdf",
        "id":'id3',
        "title":'title3',
        "time":'2019-04-19 12:00:00',
        "size":'8MB',
        "url":'http://menhu-dev.thuniwhir.com/upload/pdfFile/ADC0832_CH.pdf',//文件url
		"uploadUrl":"http://menhu-dev.thuniwhir.com/menhu-demo/file/upload",//文件上传的地址
        "autoEnterSign":true,//自动进入签批模式
        "autoEnterMark":false,//自动开启标注功能
        "readOnly":false,//只读
    }
    emp.iapppdf.openFileInner(pdf)
}

/*
    var doc = {
        id:'id2',title:'附件doc只读',time:'2019-04-19 12:00:00',size:'5MB',
        type:'doc',
        doc:{
            hostUrl:"http://www.kinggrid.com:8080/iWebOffice2009/OfficeServer.jsp",//金格服务器url
            fileId:"1487055329034",//需要编辑的文件对应的文件id  1490444371683 1487055329034
            isPGFFormat:"0",//是否以PGF格式打开
            readOnly:"1",//是否只读模式打开
            userName:"test1",//当前用户名
            isScreenshotForbid:"0",//是否防截屏
            enterReviseMode:"1",//是否进入修订模式
            showReviewingPane:"1",//是否显示修订痕迹右侧边栏,不传本参数时默认不显示,只有当enterReviseMode:"1",开启修订模式时,本参数才有效.
            hideFileMenu:"0",//是否隐藏文件菜单
            hideCopyAndCut:"0",//是否隐藏复制和剪切功能
            hideShareAndSaves:"0"//是否隐藏分享和另存为功能
        }
    }
    var preview = {
        id:'id2',
        title:'附件doc预览',
        time:'2019-04-19 12:00:00',
        size:'5MB',
        type:'preview',
        preview:{
            url:'http://menhu-dev.thuniwhir.com/upload/jingeUpload/pdf/2018081414401058861256225.doc'
        }
    }

*/
